package com.hspedu.stringbuffer_;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/4
 * @time 19:11
 */
public class Exercise02 {

    public static void main(String[] args) {
        String price = "313124.321";
        StringBuffer stringBuffer = new StringBuffer(price);

        int index = stringBuffer.lastIndexOf(".");

        for (int i = index - 3; i > 0  ; i -= 3) {
            stringBuffer = stringBuffer.insert(i,",");
        }
        System.out.println(stringBuffer);
    }
}
